/**
 * 
 */
package com.bible.test.pad.activity;

import com.bible.fire.R;
import com.bible.fire.local.CameraManager;
import com.bible.fire.pad.activity.BaseActivity;
import com.bible.fire.util.AndroidUtil;
import com.bible.fire.util.SystemConstant;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

/**
 * @author zhangyp
 *
 */
public class CameraActivity extends BaseActivity {
	
	Button watermarkBtn; 
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView( R.layout.activity_camera );
		Button button = (Button)this.findViewById(R.id.takePicture);
		watermarkBtn = (Button)findViewById(R.id.btn_watermark);
		
		button.setOnClickListener( new OnClickListener(){
			@Override
			public void onClick(View view) {
				startActivityForResult(CameraManager.takePictures(), SystemConstant.REQUEST_CODE_TAKE_PICTURE );				
			}
			
		});
		watermarkBtn.setOnClickListener( new OnClickListener(){
			@Override
			public void onClick(View view) {
				CameraManager.startCameraFromActivity( CameraActivity.this );				
			}
			
		});
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data){
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK && requestCode == SystemConstant.REQUEST_CODE_TAKE_PICTURE ) { 
			ImageView imageView = (ImageView)this.findViewById(R.id.imageView);
			if( data == null || !data.hasExtra("data") ){
				CameraManager.getImageAfterCamera( imageView );				
			}else{								
				CameraManager.actionAfterTake(requestCode, resultCode, data, imageView);
			}
		}		
	}

}
